package com.wuxi.zhang.collection;

import com.wuxi.zhang.bean.UserBean;

import java.util.Comparator;
import java.util.TreeSet;

/**
 * @author wheat on 2019/12/20.
 */
public class TreeMapTest {

    public static void main(String[] args) {

        TreeSet<UserBean> treeSet = new TreeSet<>(new Comparator<UserBean>() {
            @Override
            public int compare(UserBean o1, UserBean o2) {
                Integer o11 = o1.getAge();
                Integer o22 = o2.getAge();

                return o22.compareTo(o11);
            }
        });
        treeSet.add(new UserBean("1", 28));
        treeSet.add(new UserBean("2", 18));
        treeSet.add(new UserBean("3", 25));

        for (UserBean user : treeSet) {
            System.out.println(user.toString());
        }

    }
}
